<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Libro Bancario</title>
<link href="estilacho.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	color: #993300;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #993300;
}
a:hover {
	text-decoration: none;
	color: #993300;
}
a:active {
	text-decoration: none;
	color: #FF0000;
}
-->
</style></head>

<body>
  <?
	    	include 'conexion.php';
	extract($_POST);
    extract($_GET);
    /*$base= "ucg - copia";
	$conexion = mysql_connect("localhost","root","");
    mysql_select_db($base,$conexion);*/
       ?>
</table>
<table width="586" border="0" align="center">
  <tr>
    <td colspan="5"><img src="../css/logo.JPG" width="119" height="90" /></td>
  </tr>
  <tr>
  <th colspan="5">Libro de Banco del Mes <? echo $mes ?></th>
  </tr>
    <tr>
      <td width="142" align="center"><span class="Estilo16">Fecha</span></td>
      <td width="330" align="center"><span class="Estilo16">Explicaci&oacute;n</span></td>
      <td width="28" align="center"><span class="Estilo16">debe</span></td>
      <td width="33" align="center"><span class="Estilo16">Haber</span></td>
      <td width="31" align="center"><span class="Estilo16">Saldo</span></td>
  </tr>
    
	<?
		 
  for ($j=1; $j<=31; $j++){
 
  	 if($j<10)
	      $dia='0'.$j;
     else 
	      $dia=$j;   
	
	$mes2=$mes-1;
				   
		    for ($i=1; $i<=$mes2; $i++){
			
		if($i<10)
	      $m3='0'.$i;
        else 
	      $m3=$i;  	
		   
		  		  	  
		$fecha2="$ano"."-"."$m3"."-"."$dia"; 
		
		 $pag=mysql_query("SELECT sum(id_pago.monto_s) FROM pago, id_pago where pago.cod_p=id_pago.cod_p and pago.fecha='$fecha2' and pago.anulado!=1",$conexion);
	    while ($pago= mysql_fetch_array($pag)){
	
    $saldo=$asig-$pago[0];
	$asig=$saldo;
		
     } 
	 
	 $sqln="Select * from notas where fecha='$fecha2'";
	$resultadon=mysql_query($sqln,$conexion);
	while ($regn= mysql_fetch_array($resultadon)){  
   
    if($regn[1]==2) { $notas=$regn[3];
	      $saldo= $asig - $notas ;
		  $asig=$saldo;
		  }
		  else {
		  if($regn[1]==1) { $notas=$regn[3]; 
	      $saldo= $asig + $notas ;
		  $asig=$saldo;
		  }
		  }
		  }
		  
		$sql9=mysql_query("Select sum(monto), fecha, fondo, cheque from fondo where fecha='$fecha2' group by fondo",$conexion);
	 	 while ($reg9= mysql_fetch_array($sql9)){	?>
    
    <? $saldo=$asig+$reg9[0]; 
	   $asig=$saldo;
	   
	  }  
	      
		} } ?>   
         
		 <tr bgcolor="#33CCFF">
      <td align="center" bgcolor="#FFFFFF">&nbsp;</td>
      <td align="left" bgcolor="#FFFFFF">Saldo Anterior</td>
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td align="right" bgcolor="#FFFFFF"><? 
	  $saldo2=number_format($saldo,2,",",".");	  
	  echo $saldo2; ?>
	  
	  </td>
    </tr>   
	 
	 
	 
	 
	 
	 <?  // mes actual...........................................................................
	 
	 for ($j=1; $j<=31; $j++){
	if($j<10)
	      $dia='0'.$j;
    else 
	      $dia=$j; 
		  
	/* for ($i=1; $i<=12; $i++){	   
	   
   	   if($i<10)
	      $mes='0'.$i;
	   else 
	   	  $mes=$i;*/
		  		  	  
		$fecha="$ano"."-"."$mes"."-"."$dia";		
	
     $sql9=mysql_query("Select sum(monto), fecha, fondo, cheque from fondo where fecha='$fecha'   group by fondo",$conexion);
	 	 while ($reg9= mysql_fetch_array($sql9)){	?>
    
       <tr bgcolor="#33CCFF">
      <td align="center" bgcolor="#FFFFFF"><? echo $reg9[1] ?></td>
      <td align="left" bgcolor="#FFFFFF">Fondo N&ordm; <? echo $reg9[2] ?> Cheque N&ordm; <? echo $reg9[3] ?></td>
      <td align="right" bgcolor="#FFFFFF"><? 
	  $debe1=number_format($reg9[0],2,",",".");	  
	  echo  $debe1;  ?></td>
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td align="right" bgcolor="#FFFFFF"> <? $saldo=$saldo+$reg9[0]; 
	  $saldo2=number_format($saldo,2,",",".");	  
	  echo $saldo2; 
	  
	  
	  $asig=$saldo;?>      </td>            
    </tr>
		<? }
			
	   $pag=mysql_query("SELECT pago.cod_p, pago.cod_pago, pago.fecha, pago.anulado, pago.concepto, pago.cheque, sum(id_pago.monto_s), pago.rif, id_pago.cod_c  FROM pago, id_pago where pago.cod_p=id_pago.cod_p and pago.fecha='$fecha'group by id_pago.cod_p",$conexion);
	while ($pago= mysql_fetch_row($pag)) { 
	
	if ($pago[3]!=1){	
	$sumsaldo=$pago[6];
	$saldo=$asig-$sumsaldo;
	 
     } ?>
    <tr bgcolor="#FFFFCC">
      <td align="center" bgcolor="#FFFFFF"><? echo $pago[2] ?></td>
      <td align="left" bgcolor="#FFFFFF"><? if($pago[3]!=1){echo $pago[4] ?> s/c <? echo $pago[5]; } else  {echo $pago[4] ?> s/c <? echo $pago[5]; echo"   Anulado"; }?></td>
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td align="right" bgcolor="#FFFFFF"><? 
	  $haber1=number_format($sumsaldo,2,",",".");	  
	  echo $haber1; ?></td>
      <td align="right" bgcolor="#FFFFFF"><? 
	  $saldo2=number_format($saldo,2,",",".");	  
	  echo $saldo2; 
	  
	  
	  $asig=$saldo;?></td>
  </tr>
	<? }
	  
	$sqln="Select * from notas where fecha='$fecha'";
	$resultadon=mysql_query($sqln,$conexion);
	while ($regn= mysql_fetch_array($resultadon)){   ?>
    <tr>
      <td align="center"><? echo "$regn[2]";?></td>
      <td align="left"><? echo "$regn[4]";?></td>
      <td align="right">&nbsp;<? if($regn[1]==1)
	  $debe2=number_format($regn[3],2,",",".");	  
	  echo  $debe2; ?></td>
      <td align="right">&nbsp;<? if($regn[1]==2)
	  $haber2=number_format($regn[3],2,",",".");	  
	  echo $haber2;?></td>
      <td align="right">
	  <? if($regn[1]==2) { $notas=$regn[3];
	  $saldo= $asig - $notas ;
		  $asig=$saldo;
		  $saldo2=number_format($saldo,2,",",".");	  
	      echo $saldo2;
		   $asig=$saldo;}
		   else {
		   if($regn[1]==1) { $notas=$regn[3]; 
	       $saldo= $asig + $notas ;
		  $asig=$saldo;
		  $saldo2=number_format($saldo,2,",",".");	  
	      echo $saldo2;
		   
		   
		   $asig=$saldo;}}}
		   
		   ?> </td>   
  </tr>
	
    <? }//}?>
</table>
</body>
</html>
